package com.atguigu.srb.core.controller.admin;


import com.atguigu.common.result.R;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.vo.BorrowerApprovalVO;
import com.atguigu.srb.core.pojo.vo.BorrowerDetailVO;
import com.atguigu.srb.core.service.BorrowerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author 杜佳佳
 * @since 2021-04-13
 */
@Api(tags = "借款人管理")
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {

    @Autowired
    private BorrowerService borrowerService;


    @ApiOperation("借款人分页列表条件查询")
    @GetMapping("/queryPage")
    public R list(@RequestParam Long page,@RequestParam Long limit, @RequestParam(name = "keyword",required = false) String keyword) {
        Page<Borrower> borrowerPage = new Page<>(page, limit);
        IPage<Borrower> pageModel = borrowerService.listPage(borrowerPage,keyword);

        return R.ok().data("data",pageModel);
    }

    @ApiOperation("根据id获取借款人信息")
    @GetMapping("/info/{id}")
    public R info(@PathVariable Long id) {
        BorrowerDetailVO borrowerDetailVO = borrowerService.selectInfo(id);
        return R.ok().data("data",borrowerDetailVO);
    }

    @ApiOperation("借款额度审批")
    @PostMapping("/approval")
    public R approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO) {
        borrowerService.approval(borrowerApprovalVO);
        return R.ok().message("审批完成");
    }
}

